import {mongo} from "#nuxt-mongodb"
import { ObjectId } from "mongodb"

interface UserMes{
    userID:string
}

export default defineEventHandler(async(event)=>{
    try{
        const {userID}:UserMes = await readBody(event)
        // console.log(eventBody)
        // const userID = JSON.stringify(eventBody)
        // console.log(userID)
        const userObj = new ObjectId(userID)
        const db = mongo.db()
        const result = await db.collection('user').deleteOne({ _id: userObj });
        console.log(result)
        if(result.deletedCount == 0){
            return {
                status:404,
                message: "not found this user id"
            }
        }
        return {
            status:200,
            message: result
        }
    }catch(err:any){
        return {
            status:500,
            message: "error"
        }
    }
    
    
})